package com.example.mansystem.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.mansystem.dto.ChangeDepartmentDto;
import com.example.mansystem.entity.DepartmentDO;
import com.example.mansystem.exception.CodeAndMsg;
import com.example.mansystem.exception.UserDefinedException;
import com.example.mansystem.mapper.DepartmentMapper;
import org.apache.ibatis.jdbc.Null;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;


@Service
public class DepartmentService extends ServiceImpl<DepartmentMapper, DepartmentDO> {
    @Resource
    DepartmentMapper departmentMapper;
    public void ChangeDepartment(ChangeDepartmentDto dto)
    {
        for(int i=0;i<dto.getDeCreate().size();i++)
        {
            departmentMapper.insert(dto.getDeCreate().get(i));
        }
        for(int i=0;i<dto.getDeUpdate().size();i++)
        {
            departmentMapper.updateById(dto.getDeUpdate().get(i));
        }
        for(int i=0;i<dto.getDeDelete().size();i++)
        {
            QueryWrapper<DepartmentDO> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("departmentId",dto.getDeDelete().get(i));
            departmentMapper.delete(queryWrapper);
        }
    }
}
